const { query } = require("./mysql");
const {
	YD_setSql,
	YD_datetimeToString,
	YD_whereSql,
} = require("lib/utils/common");

/** @name 添加预约 **/
exports.yd_add = (options) => {
	const sql = `insert into ch_reservation set ${YD_setSql(options)}`;
	return query(sql);
};

/** @name 预约列表 **/
exports.yd_list = (options) => {
	const sql = `select
						yr.id, yr.number, yr.userId, yr.placeId, yr.note, yr.status,
						${YD_datetimeToString("yr.startTime")},
						${YD_datetimeToString("yr.createTime")},
						${YD_datetimeToString("yr.updateTime")},
						yu.nickname, yu.phone,
						yp.code
						from ch_reservation yr
						left join ch_user yu on yr.userId=yu.uuid
						left join ch_place yp on yr.placeId=yp.id
						order by yr.id desc
						limit ${(options.pageNum - 1) * options.pageSize},${options.pageSize}
            `;
	return query(sql);
};

/** @name 黑名单总量 **/
exports.yd_count = (options) => {
	const sql = `select count(*) as count
						from ch_reservation yr
						left join ch_user yu on yr.userId=yu.uuid
						left join ch_place yp on yr.placeId=yp.id
            `;
	return query(sql);
};

/** @name 删除车位 **/
exports.yd_delete = (id) => {
	const sql = `delete from ch_reservation where id=${id}`;
	return query(sql);
};
